home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / leda / incl / planar_m.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  4.5 KB  |  177 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  planar_map.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16.  
  17. #ifndef PLANAR_MAPH
  18. #define PLANAR_MAPH
  19.  
  20. #include <LEDA/graph.h>
  21.  
  22. class i_face;
  23.  
  24. typedef i_face* face;
  25.  
  26. class i_face {
  27.  
  28. friend class planar_map;
  29.  
  30.  edge      head;  // first edge of face
  31.  list_item loc;   // location in F_list
  32.  ent       inf;   // user defined information
  33.  
  34.  planar_map*  g;     // face of (*g)
  35.  
  36.  
  37. friend planar_map* graph_of(face f) { return f->g; }
  38.  
  39.  
  40.  i_face(ent x, planar_map* G) 
  41.  { 
  42.    inf = x ; 
  43.    head = nil; 
  44.    loc = nil; 
  45.    g = G;
  46.   }
  47.  
  48.  
  49. OPERATOR_NEW(4)
  50. OPERATOR_DEL(4)
  51.  
  52. };
  53.  
  54. declare(list,face);
  55.  
  56. declare(node_array,int)
  57.  
  58. class planar_map : public graph {
  59.  
  60. list(face)       F_list;
  61.  
  62. face  new_face(ent i=0);
  63. void  del_face(face f) { F_list.del(f->loc); delete f; }
  64. face& get_face(edge e) { return (face&)(e->contents);  }
  65. edge& get_rev(edge e)  { return (edge&)(e->adj_loc2);  }
  66.  
  67. virtual void copy_face_entry(ent& x)  const {x=x;}
  68. virtual void init_face_entry(ent& x)  const {x=0;}
  69. virtual void clear_face_entry(ent& x) const {x=0;}
  70. virtual void print_face_entry(ent& x) const {x=x;}
  71.  
  72. public:
  73.  
  74.  
  75.  planar_map(const graph&);
  76. ~planar_map();
  77.  
  78. void       init_entries();
  79.  
  80.  
  81. list(node) adj_nodes(face)   const;
  82. list(node) adj_nodes(node v) const { return graph::adj_nodes(v); }
  83.  
  84. list(edge) adj_edges(face)   const;
  85. list(edge) adj_edges(node v) const { return graph::adj_edges(v); }
  86.  
  87. list(face) all_faces()       const { return F_list; }
  88. list(face) adj_faces(node)   const;
  89.  
  90. face       adj_face(edge e)  const { return face(e->contents); }
  91.  
  92. list(edge) triangulate();
  93.  
  94. edge reverse(edge e)         const { return edge(e->adj_loc2); }
  95.  
  96. edge first_face_edge(face f) const { return f->head; }
  97. edge succ_face_edge(edge e)  const { return cyclic_adj_succ(reverse(e)); } 
  98. edge pred_face_edge(edge e)  const { return reverse(cyclic_adj_pred(e)); } 
  99.  
  100. edge next_face_edge(edge e)  const  
  101. { e = succ_face_edge(e);
  102.   return (e==adj_face(e)->head) ? nil : e;
  103. }
  104.  
  105. face first_face() const { return F_list.head(); }
  106.  
  107. face next_face(face f) const
  108. { list_item it = F_list.succ(f->loc);
  109.   return (it) ? F_list.contents(it) : nil;
  110. }
  111.  
  112.  
  113. edge       new_edge(edge,edge,ent=0);
  114. void       del_edge(edge,ent=0);
  115.  
  116. ent&       entry(face f)         { return f->inf;          }
  117. ent        inf(face f)     const { return f->inf;   }
  118. ent&       entry(node v)         { return graph::entry(v); }
  119. ent        inf(node v)     const { return graph::inf(v); }
  120.  
  121. int  straight_line_embedding(node_array(int)&, node_array(int)&);
  122.  
  123. };
  124.  
  125.  
  126. //------------------------------------------------------------------------------
  127. // PLANAR_MAP: generic planar map
  128. //------------------------------------------------------------------------------
  129.  
  130. #define PLANAR_MAP(vtype,ftype)   name3(vtype,ftype,PLANAR_MAP)
  131.  
  132. #define PLANAR_MAPdeclare2(vtype,ftype)\
  133. \
  134. class PLANAR_MAP(vtype,ftype) : public planar_map {\
  135. \
  136. void init_node_entry(ent& x)  const { vtype y=0; x = Copy(y); }\
  137. void init_face_entry(ent& x)  const { ftype y=0; x = Copy(y); }\
  138. \
  139. void copy_node_entry(ent& x)  const { Copy(*(vtype*)&x); }\
  140. void copy_face_entry(ent& x)  const { Copy(*(ftype*)&x); }\
  141. \
  142. void clear_node_entry(ent& x) const { Clear(*(vtype*)&x); }\
  143. void clear_face_entry(ent& x) const { Clear(*(ftype*)&x); }\
  144. \
  145. public:\
  146. \
  147.    vtype  inf(node v)         const   { return vtype(planar_map::inf(v)); }\
  148.    ftype  inf(face f)         const   { return ftype(planar_map::inf(f)); }\
  149.    vtype& entry(node v)          { return *(vtype*)&(planar_map::entry(v)); }\
  150.    ftype& entry(face f)          { return *(ftype*)&(planar_map::entry(f)); }\
  151.    vtype& operator[] (node v)    { return entry(v); }\
  152.    ftype& operator[] (face f)    { return entry(f); }\
  153. \
  154.    edge   new_edge(edge e1, edge e2)\
  155.                           { return planar_map::new_edge(e1,e2,0); }\
  156.    edge   new_edge(edge e1, edge e2, ftype a)\
  157.                           { return planar_map::new_edge(e1,e2,Ent(a)); }\
  158. \
  159. void print_node(node v) const { cout << "["; Print((vtype&)(entry(v))); cout << "]";}\
  160. \
  161.    PLANAR_MAP(vtype,ftype)(const GRAPH(vtype,ftype)& G) : ((graph&)G)   {}\
  162.    ~PLANAR_MAP(vtype,ftype)()     { clear(); }\
  163. \
  164. };
  165.  
  166.  
  167. #define forall_face_edges(e,F)\
  168. for(e=graph_of(F)->first_face_edge(F); e; e=graph_of(F)->next_face_edge(e)) 
  169.  
  170. #define forall_faces(f,G)\
  171. for(f=G.first_face(); f; f=G.next_face(f)) 
  172.  
  173.  
  174.  
  175. #endif PLANAR_MAPH
  176.